package com.yanftch.hdc_tools.test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class GitExecutor {
    public static void main(String[] args) {
        String command = "git status"; // 示例命令，可以替换为其他 Git 命令

        try {
            ProcessBuilder processBuilder = new ProcessBuilder();
            processBuilder.command("bash", "-c", command); // 使用 bash 执行命令

            Process process = processBuilder.start();

            // 获取输出
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

            // 等待命令执行完毕
            int exitCode = process.waitFor();
            System.out.println("Exited with code: " + exitCode);
        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
